/* Copyright (c) 2004-2023 Peigen.info. All rights reserved. */
package info.peigen.hotpot.demo.service.socket;


import cn.hutool.core.util.HexUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;
import org.smartboot.socket.transport.AioSession;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * <b>(StringClient)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-08-12
 */
public class StringClient {
    public static void main(String[] args) throws IOException {
        String     path      = "D:\\Temp\\files\\device\\session.dat";
        byte[]     b         = Files.readAllBytes(Path.of(path));
        AioSession session   = (AioSession) JSON.parse(b, JSONReader.Feature.EmptyStringAsNull);
        String     sessionId = session.getSessionID();
        System.out.println(sessionId);
    }

    public static void send(String sessionId) {
        // AioSession session = SocketProtocol.CHANNEL_MAP.get(sessionId);
        // // 读取环境数据
        // byte[] b = HexUtil.decodeHex("01030000F1D8");
        //
        // // 读取设备ID
        // b = HexUtil.decodeHex("0103006000044417");
        //
        // // 读取系统参数配置
        // // b = HexUtil.decodeHex("01030020F000");
        // try {
        //     session.writeBuffer().write(b);
        //     session.writeBuffer().flush();
        // } catch (IOException e) {
        //     throw new RuntimeException(e);
        // }
    }
}
